<%@ page autoFlush="false" import="java.util.*,java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*" %>

<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
%>
<%!
Color getRandColor(int fc,int bc){
          Random random = new Random();
          if(fc>255) fc=255;
          if(bc>255) bc=255;
          int r=fc+random.nextInt(bc-fc);
          int g=fc+random.nextInt(bc-fc);
          int b=fc+random.nextInt(bc-fc);
          return new Color(r,g,b);
          }
%>
<%
String chose="23456789abcdefghijkmnpqrstuvwxyz";

char display[]={'0',' ','0',' ','0',' ','0'},ran[]={'0','0','0','0'},temp;

Random rand=new Random();

for(int i=0;i<4;i++)
{

temp=chose.charAt(rand.nextInt(chose.length()));

display[i*2]=temp;

ran[i]=temp;
}

String random=String.valueOf(display);
session.setAttribute("random",String.valueOf(ran));
%>
<%

          //out.clear();
          response.setContentType("image/jpeg");
          response.addHeader("pragma","NO-cache");
          response.addHeader("Cache-Control","no-cache");
          response.addDateHeader("Expries",0);
          int width=80, height=30;
          BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          Graphics g = image.getGraphics();

          g.setColor(getRandColor(240,242));
          g.fillRect(0, 0, width, height);

         //g.setColor(getRandColor(220,250));
          g.setFont(new Font("Times New Roman",Font.PLAIN,21));

          g.setColor(getRandColor(100,160));
    for (int i=0;i<10;i++)
          {
          int x = rand.nextInt(width);
          int y = rand.nextInt(height);
          int xl = rand.nextInt(12);
          int yl = rand.nextInt(12);
          g.drawLine(x,y,x+xl,y+yl);
          }
          g.drawString(random,5,25);
          g.dispose();
          ServletOutputStream outStream = response.getOutputStream();
          JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream);
          encoder.encode(image);
          //pageContext.pushBody();
          outStream.close();
          out.clear();
          out = pageContext.pushBody();

          
     %>


